package vip.xiaonuo.pm.modular.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.param.DeleteByIdParam;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.pm.modular.project.param.PmProjectTypeAddParam;
import vip.xiaonuo.pm.modular.project.param.PmProjectTypeEditParam;
import vip.xiaonuo.pm.modular.project.service.PmProjectTypeService;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 项目类型 前端控制器
 * </p>
 *
 * @author xhs
 * @since 2025-06-04
 */
@Tag(name = "项目类型控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@Validated
@RestController
@RequestMapping("/pm/projectType/")
public class PmProjectTypeController {

    @Resource
    private PmProjectTypeService pmProjectTypeService;

    /**
     * 新增项目类型
     *
     * @param pmProjectTypeAddParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "新增项目类型")
    @CommonLog("新增项目类型")
    @SaCheckPermission("/pm/projectType/add")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid PmProjectTypeAddParam pmProjectTypeAddParam) {
        pmProjectTypeService.add(pmProjectTypeAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑项目类型
     *
     * @param pmProjectTypeEditParam 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "编辑项目类型")
    @CommonLog("编辑项目类型")
    @SaCheckPermission("/pm/projectType/edit")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid PmProjectTypeEditParam pmProjectTypeEditParam) {
        pmProjectTypeService.edit(pmProjectTypeEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除项目类型
     *
     * @param DeleteIdParamList 入参
     * @return CommonResult<String>
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "删除项目类型")
    @CommonLog("删除项目类型")
    @SaCheckPermission("/pm/projectType/delete")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空") List<DeleteByIdParam> DeleteIdParamList) {
        pmProjectTypeService.delete(DeleteIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取项目类型树
     *
     * @return CommonResult<List<Tree<String>>>
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "获取项目类型树")
    @SaCheckPermission("/pm/projectType/tree")
    @PostMapping("/tree")
    public CommonResult<List<Tree<String>>> tree(){
        return CommonResult.data(pmProjectTypeService.tree());
    }
}
